package com.jsmile.cloud.msgcenter.pay.repo;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jsmile.cloud.msgcenter.pay.dao.PayInfoDao;
import com.jsmile.cloud.msgcenter.pay.model.PayInfo;
import com.jsmile.mall.api.enums.JSmileCacheEnum;
import com.jsmile.mall.api.exception.ExceptionKit;

import lombok.extern.slf4j.Slf4j;

/**
 * @author 龚亮
 * @version 1.0
 * @desc 为了薪资破万，还是睡一会儿吧...!
 * @date 2020年06月07日 11:19:01
 */
@Service
@Slf4j
@Transactional(readOnly = true, rollbackFor = Exception.class)
public class PayInfoSearchRepository extends ServiceImpl<PayInfoDao, PayInfo> {

    @Cacheable(value = JSmileCacheEnum.JSmileCacheName.oneMonth, key = "'tenantId_'+#tenantId+'payType_'+#payType")
    public PayInfo findByPayType(long tenantId, int payType) {
        PayInfo payInfo = this.baseMapper.selectOne(new QueryWrapper<PayInfo>().lambda().eq(PayInfo::getTenantId, tenantId).eq(PayInfo::getPayType, payType));
        ExceptionKit.checkNotNull(payInfo, "支付信息不存在!");
        return payInfo;
    }
}
